    //
//  UPRegisterViewController.mm
//  UPai
//
//  Created by zhan ky on 11-10-9.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "UPRegisterViewController.h"


@implementation UPRegisterViewController
@synthesize m_loginTableView;
@synthesize m_dataArray;
@synthesize m_mainDelegate;
// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
    }
    return self;
}
*/
- (void)cancelButtonPressed
{
	[self dismissModalViewControllerAnimated:YES];
}

- (void)registButtonPressed
{
	[m_mainDelegate ChangeToMainUI];
}

- (void)setupTableView
{
	if (!m_dataArray) {
		self.m_dataArray = [NSMutableArray arrayWithObjects:@"用户名/Email",@"密码",@"确认密码",@"邮件",nil];
	}
	
	self.m_loginTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 20+RowHeight*[m_dataArray count]) style:UITableViewStyleGrouped];
	m_loginTableView.delegate = self;
	m_loginTableView.dataSource = self;
	m_loginTableView.rowHeight = RowHeight;
	m_loginTableView.backgroundColor = [UIColor grayColor];
	[self.view addSubview:m_loginTableView];
	m_loginTableView.scrollEnabled = NO;
	
}


// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView 
{
	[super loadView];
	self.view.backgroundColor = [UIColor grayColor];
	
	self.navigationItem.title = @"创建免费用户";
	
	UIBarButtonItem * cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"取消" 																
																style:UIBarButtonItemStyleBordered
																target:self		
																action:@selector(cancelButtonPressed)];
	
	self.navigationItem.leftBarButtonItem = cancelButton;
	
	UIBarButtonItem * registButton = [[UIBarButtonItem alloc] initWithTitle:@"注册" 																
																	   style:UIBarButtonItemStyleBordered
																	  target:self		
																	  action:@selector(registButtonPressed)];
	self.navigationItem.rightBarButtonItem = registButton;
	
	[self setupTableView];
}

- (UITextField *)GetTxtField:(NSUInteger)index
{
	
	CGRect frame = CGRectMake(kLeftMargin, (RowHeight-kTextFieldHeight)/2, kTextFieldWidth, kTextFieldHeight);
	UITextField * txtField = [[[UITextField alloc] initWithFrame:frame] autorelease];
	txtField.borderStyle = UITextBorderStyleNone;
	txtField.textColor = [UIColor blackColor];
	txtField.font = [UIFont systemFontOfSize:17];
	txtField.placeholder = [self.m_dataArray objectAtIndex:index];
	txtField.backgroundColor = [UIColor whiteColor];
	txtField.autocorrectionType = UITextAutocorrectionTypeNo;
	txtField.keyboardType = UIKeyboardTypeDefault;
	txtField.returnKeyType = UIReturnKeyDone;
	txtField.clearButtonMode = UITextFieldViewModeWhileEditing;
	txtField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
	txtField.tag = index;
	txtField.delegate = self;
	
	return txtField;
}


#pragma mark UITableViewDataSource methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
	return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
	return [self.m_dataArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
	NSString *identifier = @"loginCell";
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
	if (!cell) {
		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
									   reuseIdentifier:identifier] autorelease];
	}else {
		
	}
	cell.selectionStyle = UITableViewCellSelectionStyleNone;
	cell.backgroundColor = [UIColor whiteColor];
	//配置单元格
	//	cell.textLabel.text = [[dataArray objectAtIndex:indexPath.row] valueForKey:kSourceKey];
	UITextField *tmpTxtField = [self GetTxtField:indexPath.row];
	[cell.contentView addSubview:tmpTxtField];
	
	return cell;
}


/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
	[m_dataArray release];
	[m_loginTableView release];
    [super dealloc];
}


@end
